package io;

import java.io.*;
import java.util.Scanner;
//进行普通文件的复制
public class IODemo14 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要复制的源文件");
        String srcPath = sc.next();
        System.out.println("请输入要复制的目标文件");
        String desPath = sc.next();
        File srcFile = new File(srcPath);
        if(!srcFile.isFile()){
            System.out.println("输入路径有误");
            return;
        }
        File desFile = new File(desPath);
        if(!desFile.getParentFile().isDirectory()){
            System.out.println("输入路径有误");
            return;
        }
        try(InputStream inputStream = new FileInputStream(srcFile);
        OutputStream outputStream = new FileOutputStream(desFile)){

            while(true){
                byte[] buffer = new byte[1024];
                int n = inputStream.read(buffer);
                if(n == -1){
                    break;
                }
                outputStream.write(buffer,0,n);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
